# 处理tushare数据
import datetime
import numpy as np
import pandas as pd

class DataProcessor:
    def __init__(self):
        pass

    def process_data(self, marketdata: dict) -> dict:
        if marketdata['type'] == 'daily':
            marketdata['data'] = self._process_type_daily_data(marketdata['data'])
            return marketdata
        else:
            raise ValueError("Unsupported market_data format")

    def _process_type_daily_data(self, data: pd) -> np.array:
        c_len = data.shape[0]
        total_res = []
        for j in range(c_len):
            resu0 = list(data.iloc[c_len - 1 - j])
            resu = []
            for k in range(len(resu0)):
                if str(resu0[k]) == 'nan':
                    resu.append(-1)
                else:
                    resu.append(resu0[k])

            # To search https://tushare.pro/webclient/ understand detail
            total_res.append(resu)
        processed_data = pd.DataFrame(total_res, columns=data.columns)
        return processed_data


